<template>
  <div class="wrapper">
    <swiper :options="swiperOption" v-if="showSwiper">
      <!-- 添加v-if="List.length"  当传递进来的值是一个空数组的时候v-if的值是false swiper不会被创建，只有当真正的数据过来后，才会被创建-->
        <swiper-slide v-for="item of swiperList" :key="item.id">
          <img :src="item.imgUrl" alt="" class="swiper-img">
        </swiper-slide>
        <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    swiperList: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true
      }
      /* swiperList: [{
        id: '001',
        imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20193/ed5f4115226306e48e6fad106a038afe.jpg_750x200_64df48d6.jpg'
      }, {
        id: '002',
        imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20193/278a88f18f1523eec8c52f650522be68.jpg_750x200_bc365244.jpg'
      }] */
    }
  },
  computed: {
    showSwiper () {
      return this.swiperList.length
    }
  }
}
</script>

<style scoped>
  .wrapper {
    overflow: hidden;
    width: 100%;
  }
  .swiper-img {
    width: 100%;
    height: 100%;
  }
  /* 样式穿透 */
  .wrapper >>> .swiper-pagination-bullet-active {
    background: #fff;
  }
</style>
